<?php
namespace App\Logic\SalesReport;

use App\Models\Product\ProductAmazonSku;
use App\Models\SalesReport\PaymentDetail as TPaymentDetail;
use Illuminate\Support\Facades\DB;
class PaymentDetailCommonUp
{
    public static function exePayment($date){
        try{
            DB::beginTransaction();
            TPaymentDetail::query()
                ->where('report_date',$date)
                ->where('is_common',1)
                ->where('country_id','<>',0)
                ->where('seller_sku','<>','0')
                ->orderBy('id')
                ->chunk(100, function ($re){
                    foreach ($re as $_re){
                        $pas = ProductAmazonSku::query()
                            ->where('country_id',$_re->country_id)
                            ->where('seller_sku',$_re->seller_sku)
                            ->first();
                        if(!$pas){
                            continue;
                        }
                        $_re->account_id = $pas->account_id;
                        $_re->seller_id = $pas->seller_id;
                        $flag = $_re->save();
                        if($flag){
                            echo '---'.$_re->id.'成功！@'.PHP_EOL;
                        }
                    }
                });
            DB::commit();
        }catch (\Exception $e){
            DB::rollBack();
            report($e);
        }
    }
}
